package net.dipper.tankwar.editor.ui;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import net.dipper.tankwar.core.helper.ViewPort;
import wnb.util.ui.AnimationPane;

public class MapPane extends AnimationPane implements MouseMotionListener, MouseListener {	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private EditorContext context;
	
	public MapPane(EditorContext context, int delay, boolean loop) {
		super(delay, loop);
		
		this.context = context;
		EditorAnimation animation = new EditorAnimation(this.context);
		setAnimation(animation);
		addMouseMotionListener(this);
		addMouseListener(this);
		
		setPreferredSize(new Dimension(600, 600));
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		Point p = e.getPoint();
		Dimension s = getSize();
		ViewPort v = this.context.getViewPort();
		int gW = s.width / v.width;
		int gH = s.height / v.height;
		int i = p.x/gW;
		int j = p.y/gH;
		
		this.context.setCursor(i, j);
	}

	@Override
	public void mouseClicked(MouseEvent event) {
			if(context.getMode() == EditorContext.MODE_EDIT){
				context.add();
			}else{
					context.select();
			}
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
